// 通用类型定义文件

// 用户接口
export interface User {
  id: string
  username: string
  email: string
  password?: string
  role: 'admin' | 'student'
  createdAt: string
  updatedAt: string
  profile: {
    firstName: string
    lastName: string
    avatar: string
    phone: string
  }
}

// 登录请求接口
export interface LoginRequest {
  username: string
  password: string
}

// 注册请求接口
export interface RegisterRequest {
  username: string
  email: string
  password: string
  confirmPassword: string
  firstName: string
  lastName: string
  phone?: string
}

// 认证状态接口
export interface AuthState {
  isAuthenticated: boolean
  user: User | null
  token: string | null
}

// 提交记录接口
export interface Submission {
  id: number
  assignmentTitle: string
  code: string
  timestamp: Date
  status: '已提交' | '已通过' | '需要修改'
  grade?: string
  score?: number
  feedback?: string
}

// 状态消息接口
export interface StatusMessage {
  show: boolean
  text: string
  type: 'success' | 'error' | 'warning' | 'info'
}

// 作业接口
export interface Assignment {
  id: number
  title: string
  description: string
  difficulty: 'easy' | 'medium' | 'hard'
  estimatedTime: string
  requirements: string[]
}

// 评分详情接口
export interface GradingDetails {
  score: number
  maxScore: number
  feedback: string
}

// 评分结果接口（从 util.ts 导入）
export interface GradingResult {
  score: number
  maxScore: number
  details: {
    visual: {
      score: number
      maxScore: number
      feedback: string
    }
  }
  feedback: string
  grade: string
}

// 代码编辑器配置接口
export interface EditorConfig {
  fontSize: number
  fontFamily: string
  theme: 'light' | 'dark'
  autoPreview: boolean
  previewDelay: number
}

// 键盘快捷键配置
export interface KeyboardShortcuts {
  preview: string
  submit: string
  reset: string
  clear: string
}

// 应用配置接口
export interface AppConfig {
  editor: EditorConfig
  shortcuts: KeyboardShortcuts
  autoSave: boolean
  autoSaveInterval: number
}

// 工具函数类型
export type StatusType = StatusMessage['type']
export type DifficultyLevel = Assignment['difficulty']
export type SubmissionStatus = Submission['status']

// 常量定义
export const DIFFICULTY_LABELS: Record<DifficultyLevel, string> = {
  easy: '简单',
  medium: '中等',
  hard: '困难'
}

export const STATUS_LABELS: Record<SubmissionStatus, string> = {
  '已提交': '已提交',
  '已通过': '已通过',
  '需要修改': '需要修改'
}

// 评分阈值常量已移至 @/config/constants.ts 文件中

// 类型守卫函数
export function isValidSubmission(obj: any): obj is Submission {
  return (
    typeof obj === 'object' &&
    obj !== null &&
    typeof obj.id === 'number' &&
    typeof obj.assignmentTitle === 'string' &&
    typeof obj.code === 'string' &&
    obj.timestamp instanceof Date &&
    ['已提交', '已通过', '需要修改'].includes(obj.status)
  )
}

export function isValidGradingResult(obj: any): obj is GradingResult {
  return (
    typeof obj === 'object' &&
    obj !== null &&
    typeof obj.score === 'number' &&
    typeof obj.maxScore === 'number' &&
    typeof obj.feedback === 'string' &&
    typeof obj.grade === 'string' &&
    obj.details &&
    typeof obj.details === 'object'
  )
}